$(function () {
    //注册事件
    var colors = ["red", "green", "hotpink", "pink", "cyan", "yellowgreen", "purple", "deepskyblue"];
    $("#btn").click(function () {
        var randomColor = parseInt(Math.random() * colors.length);
        var randomY = parseInt(Math.random() * 700);
        $("<span></span>")//创建span
            .text($("#text").val())//设置内容
            .css("color", colors[randomColor])//设置字体颜色
            .css("left", "1899px")//设置left值
            .css("top", randomY)//设置top值
            .animate({left: -500}, 10000, "linear", function () {
                //到了终点，需要删除
                $(this).remove();
            })//添加动画
            .appendTo("#screen-frame");
        $("#text").val("");
    });
    $("#text").keyup(function (e) {
        if (e.keyCode == 13) {
            $("#btn").click();
        }
    });

});